//
//  YueJuanViewController.m
//  SanYiTeaching
//
//  Created by 李文强 on 2019/4/3.
//  Copyright © 2019 李文强. All rights reserved.
//

#import "YueJuanViewController.h"
#import "SYFunctionView.h"
#import "SYFunctoinModel.h"
#import "SYSilaViewController.h"
#import "SYTongJiViewController.h"
#import "SYPiGaiViewController.h"
#import "JiaoCueZuoYeCollectionView.h"

@interface YueJuanViewController ()<JiaoXueZuoYeDelegate>
@property (strong, nonatomic) SYFunctionView *functionView;
@property (strong, nonatomic) NSMutableArray *numberArr;
@property (strong, nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) SYTongJiViewController *tongjiVC;//统计
@property (strong, nonatomic) SYPiGaiViewController *piGaiVC;//批改

@property (strong, nonatomic) NSMutableArray *dataArr;//本身就存在的vc
@property (strong, nonatomic) NSMutableArray *selectDataArr;//选中得vc
@property (strong, nonatomic) UIView *baseView;//

@property (strong, nonatomic) SYSilaViewController *currentVC;

@property (nonatomic, strong) JiaoCueZuoYeCollectionView *zuoYeVC;


@end

@implementation YueJuanViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
    self.numberArr = [[SYFunctoinModel alloc] yueJuanShuJu];
    _functionView = [[SYFunctionView alloc] initWithFrame:CGRectMake(0, 20, 215, APP_HEIGHT - 20)];
    [_functionView showFunctionView:_functionView vc:self listDataArr:self.numberArr];
    _functionView.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
    _functionView.curTableView.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
    [self.view addSubview:_functionView];
   // [self.view addSubview:self.scrollView];
    __weak typeof(self) weakSelf = self;
    _functionView.block = ^(SYFunctoinModel *model, NSInteger index) {
        [weakSelf switchInterfaceIndex:index];
    };
    self.dataArr = [NSMutableArray new];
    self.selectDataArr = [NSMutableArray new];
    
    [self.view addSubview:self.baseView];
    [self.baseView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.functionView.mas_right);
        make.top.equalTo(@20);
        make.right.equalTo(@0);
        make.bottom.equalTo(self.view.mas_bottom);
    }];
    
    
    for (NSInteger i = 0; i <self.numberArr.count; i++) {
        if (self.numberArr.count == 0) {
            return;
        }

        
        SYFunctoinModel *function = self.numberArr[i];
        if ([function.titleName containsString:@"批改"]) {
            self.piGaiVC = [[SYPiGaiViewController alloc] init];
            [self.baseView addSubview:self.piGaiVC.view];
            [self.piGaiVC.view mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.left.equalTo(self.baseView);
                make.right.equalTo(self.baseView.mas_right).offset(0);
                make.bottom.equalTo(self.baseView.mas_bottom).offset(0);
            }];
            [self.dataArr addObject:self.piGaiVC];
            
        } else if ([function.titleName containsString:@"统计"]) {
//            self.tongjiVC = [[SYTongJiViewController alloc] init];
//            [self.dataArr addObject:self.tongjiVC];
            UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
            
            _zuoYeVC = [[JiaoCueZuoYeCollectionView alloc]initWithCollectionViewLayout:flow];
            _zuoYeVC.mDelegate = self;
            _zuoYeVC.view.frame = CGRectMake(0, 0, APP_WIDTH, APP_HEIGHT);
            [self.dataArr addObject:_zuoYeVC];
        }
    }
   // [(SYSilaViewController *) self.childViewControllers[0] viewDidSlidInto];
    
}
- (void)selectItem {
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
    _functionView.indexPath = indexPath;
    [self switchInterfaceIndex:1];
}

//切换界面
- (void)switchInterfaceIndex:(NSInteger)index {
    SYSilaViewController *vc = self.dataArr[index];
    
    if (self.currentVC == vc) {
        return;
    } else {
        [self addChildViewController:vc];
        vc.view.hidden = NO;
        [self.baseView addSubview:vc.view];
        [vc.view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.baseView);
            make.right.equalTo(self.baseView.mas_right).offset(0);
            make.bottom.equalTo(self.baseView.mas_bottom).offset(0);
        }];
        //替换view
        [vc didMoveToParentViewController:self];
        [self.currentVC willMoveToParentViewController:nil];
        [self.currentVC removeFromParentViewController];
        [self.currentVC.view removeFromSuperview];
        self.currentVC.view.hidden = YES;
    }
    if (index == 1) {
        [self.tongjiVC viewDidSlidInto];
    }
    
//    [(SYSilaViewController *) self.childViewControllers[index] viewDidSlidInto];
}
- (void)jiaoXueZuoYeDelegateCollectionViewCellClick:(NSIndexPath *)index{
    
}
#pragma mark - setget
- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.scrollEnabled = NO;
    }
    return _scrollView;
}

- (UIView *)baseView {
    if (!_baseView) {
        _baseView = [[UIView alloc] init];
    }
    return _baseView;
}


@end




























